package com.syyo.admin.controller;

import com.syyo.admin.common.anno.AnonymousAccess;
import com.syyo.admin.domain.FileUpload;
import com.syyo.admin.domain.ResultVo;
import com.syyo.admin.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther: wangzhong
 * @Date: 2020/8/18 10:17
 * @Description:
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 上传
     * @param file
     */
    @PostMapping("/upload")
    public ResultVo<FileUpload> upload(MultipartFile file) {
        return fileService.uploadFile(file);
    }

    /**
     * 下载
     * @param
     */
    @AnonymousAccess
    @GetMapping("/download")
    public void download(@RequestParam("fileName")String fileName, @RequestParam("uuid")String uuid, HttpServletResponse response) throws IOException {
        fileService.downloadFile(fileName,uuid,response);
    }

}
